import request from './auth'

// ==================== 用户端接口 ====================

/**
 * 获取订单详情
 * @param {Number} id - 订单ID
 * @returns {Promise}
 */
export function getOrderDetail(id) {
    return request({
        url: `/user/order/${id}`,
        method: 'get'
    })
}

/**
 * 分页查询买家订单列表
 * @param {Number} pageNum - 页码
 * @param {Number} pageSize - 每页记录数
 * @param {Number} userId - 买家ID
 * @param {Number} orderStatus - 订单状态
 * @returns {Promise}
 */
export function getBuyerOrders(pageNum = 1, pageSize = 10, orderStatus = null) {
    return request({
        url: '/user/order/buyer',
        method: 'get',
        params: { pageNum, pageSize, orderStatus }
    })
}

/**
 * 分页查询卖家订单列表
 * @param {Number} pageNum - 页码
 * @param {Number} pageSize - 每页记录数
 * @param {Number} sellerId - 卖家ID
 * @param {Number} orderStatus - 订单状态
 * @returns {Promise}
 */
export function getSellerOrders(pageNum = 1, pageSize = 10, orderStatus = null) {
    return request({
        url: '/user/order/seller',
        method: 'get',
        params: { pageNum, pageSize, orderStatus }
    })
}

/**
 * 取消订单
 * @param {Number} id - 订单ID
 * @returns {Promise}
 */
export function cancelOrder(id) {
    return request({
        url: `/user/order/${id}/cancel`,
        method: 'put'
    })
}

/**
 * 支付订单
 * @param {Number} id - 订单ID
 * @returns {Promise}
 */
export function payOrder(id) {
    return request({
        url: `/user/order/${id}/pay`,
        method: 'put'
    })
}

/**
 * 确认收货
 * @param {Number} id - 订单ID
 * @returns {Promise}
 */
export function confirmOrder(id) {
    return request({
        url: `/user/order/${id}/confirm`,
        method: 'put'
    })
}

/**
 * 发货
 * @param {Number} id - 订单ID
 * @param {String} trackingNumber - 物流单号
 * @returns {Promise}
 */
export function shipOrder(id, trackingNumber) {
    return request({
        url: `/user/order/${id}/ship`,
        method: 'put',
        params: { trackingNumber }
    })
}

// ==================== 管理端接口 ====================

/**
 * 获取订单详情
 * @param {Number} id - 订单ID
 * @returns {Promise}
 */
export function getOrderDetailAdmin(id) {
    return request({
        url: `/admin/order/${id}`,
        method: 'get'
    })
}

/**
 * 分页查询所有订单列表
 * @param {Number} page - 页码
 * @param {Number} pageSize - 每页记录数
 * @param {String} auctionTitle - 拍卖品标题
 * @param {String} number - 订单编号
 * @param {Number} orderStatus - 订单状态
 * @returns {Promise}
 */
export function getAllOrders(page = 1, pageSize = 10, auctionTitle = null, number = null, orderStatus = null) {
    return request({
        url: '/admin/order/page',
        method: 'get',
        params: { page, pageSize, auctionTitle, number, orderStatus }
    })
}

